/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package physical_spaces.business;

import Entity.DataFile;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.enterprise.inject.New;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import login.beans.ConectionBean;
import physical_spaces.DAO.CreateDataFileDAO;
import physical_spaces.DAO.ManagementDataFileDAO;

/**
 *
 * @author juan
 */
public class CreateDataFileBusiness {

    String tableSpaceName;
    String dataFileName;
    String size;
    boolean automaticExtend;
    String autoExtend;
    String max;
    public Connection conn;
    
    
    public CreateDataFileBusiness(String tableSpaceName, String dataFileName, String size, boolean automaticExtend, String autoExtend, String max) {
        this.tableSpaceName = tableSpaceName;
        this.dataFileName = dataFileName;
        this.size = size;
        this.automaticExtend = automaticExtend;
        this.autoExtend = autoExtend;
        this.max = max;
        
    }

                
    public void createDataFile( Connection conn ) {
        try {
            String sql;
            sql = "ALTER TABLESPACE \"" + tableSpaceName + "\" ADD DATAFILE '" + dataFileName + "SIZE " + size+"k";
            if (automaticExtend) {
                sql += " AUTOEXTEND ON";
                if (!autoExtend.equals("")) {
                    sql += " NEXT " + autoExtend +"k";
                }
                if (!max.equals("")) {
                    sql += " MAXSIZE " + max+"k";
                }
            } else {
                sql += " AUTOEXTENT OFF";
            }
            
           
            
            new CreateDataFileDAO(sql, conn);
        } catch (SQLException ex) {
            Logger.getLogger(CreateDataFileBusiness.class.getName()).log(Level.SEVERE, null, ex);
        }

    }

}


